package com.kungfu.task;

import com.kungfu.service.ZzdService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduledTask {
    protected Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private ZzdService zzdService;

    @Scheduled(cron = "0 0 2 * * ?") //每天 早上两点触发 即 2:00 触发
    public void executeGotDataTask() {
        logger.debug(new Date().toString() + "开始清理过期或者将要完结的门诊转诊单......");
        try {
            handleZzdTable();
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage() + e.toString());
        }
    }

    private void handleZzdTable() {
        try{
            zzdService.updateZzdRecord();
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage() + e.toString());
        }

    }
}
